{% comment %}
/* Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
{% endcomment %}
{% extends 'base.html' %}
{% block content %}


{% if no_posts_found or bad_date_request %}
  {% if no_posts_found %}
    Sorry, we couldn't find any posts.
  {% else %}
    Check the supplied date in the requested URL. It appears wrong.
  {% endif %}
{% else %}

  {% comment %}User wants posts for a spcified date range.{% endcomment %}
  {% if date_query %}
    {% for post in posts %}
    <div class="cc-post">
      <div class="cc-post-head">
        <a class="cc-post-title"
          href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
          {{post.title}}
        </a>
      </div>
      <div class="cc-post-body">{{post.body|striptags|truncatewords:"50"}}</div>
      {% if blog.enable_comments %}
      <div class="cc-post-foot">
        <a href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">Comments ({{post.comment_count}})</a>
      </div>
      {% endif %}
    </div>
    {% endfor %}
  {% else %}
    {% comment %}User wants a specific post.{% endcomment %}
    {% if post %}
      <div class="cc-post">
        <div class="cc-post-head">
          <a
            class="cc-post-title"
            href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
            {{post.title|title}}
          </a>
          <div>
            {% if blog.enable_postinfo %}
            By {{post.author.nickname}}
            On {{post.publish_date|date:"F j, Y"}}
            {% endif %}
            {% if blog.enable_comments %} -
            <a href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">Comments ({{post.comment_count}})</a>
            {% endif %}
          </div>
        </div>
        <div class="cc-post-body">
          {{post.body}}
        </div>
        {% if blog.enable_comments %}
        <div class="cc-post-foot">
          <a href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">Comments ({{post.comment_count}})</a>
        </div>
        {% endif %}
      </div>

      {% if blog.enable_comments %}
        <div id="cc-post-comments">
          <a href="#" name="comments"></a>Comments:
        </div>
  
        {% comment %}
          Start the comments section.
        {% endcomment %}
  
        {% for comment in post_comments %}
        <div>
          {{comment.date_time|date:"F j, Y @ P"}}<br />
          <a href="#" name="{{comment.key}}"></a>
          {% if comment.author.url %}
            <a href="{{comment.author.url}}">
              {{comment.author.nickname}}
            </a>
          {% else %}
            {{comment.author.nickname}}
          {% endif %}
          said{% if comment.rely_to %}
            to
          <a href="#{{comment.reply_to.key}}">
            {{comment.reply_to.author.nickname}}
          </a>
          {% endif %}, <br />
          {{comment.body}}
          {% ifequal comment.status 'unreviewed' %}
            <br>
            {% if is_admin %}
              Unreviewed
            {% else %}
              Awaiting review.
            {% endif %}
          {% endifequal %}
        </div>
        {% endfor %}
        <hr />
  
        {% comment %}
          Start comment form.
        {% endcomment %}
  
        {% if user %}
          <form method="post">
            <input type="hidden" name="post" value="{{post.key|addslashes}}">
            <input type="hidden" name="author" value="{{user.key|addslashes}}">
            <input
              type="text"
              name="nickname"
              value='{{user.nickname|default_if_none:"Anonymous"|addslashes}}'>
              (Nickname)
              {% if warnings.nickname %}
                Your nickname shouldn't be blank.
              {% endif %}
            <br />
            <input
              type="text"
              name="url"
              value='{{user.url|default_if_none:""|addslashes}}'> (Url)
              {% if warnings.url %}
                Double check your url and don't forget the http://.
              {% endif %}
            <br />
            {% if warnings.body %}
              Don't forget to make your comment!<br>
            {% endif %}
            <textarea name=body>{{comment.body|escape}}</textarea>
            <br />
            <input type=submit name=new-comment value="Post Comment">
          </form>
        {% else %}
          You need to <a href='{{login_url}}'>login</a> to comment.
        {% endif %}
      {% endif %}
    {% else %}

      {% comment %}
        Couldn't find what the user wanted, so instead, we'll show some
        possible suggestions.
      {% endcomment %}

      {% if are_suggested_posts %}
        Couldn't find exactly what you asked for, but here are some suggestions:
        <br />
      {% else %}
        More than one match for your request:<br />
      {% endif %}

      {% for post in possible_posts %}
      <div class="cc-post">
        <div class="cc-post-head">
          <a class="cc-post-title"
            href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}">
            {{post.title}}
          </a>
        </div>
        <div class="cc-post-body">
          {{post.body|striptags|truncatewords:"50"}}
        </div>
        {% if blog.enable_comments %}
        <div class="cc-post-foot">
          <a href="/{{post.publish_date|date:"Y/m/d"}}/{{post.path|urlencode}}#comments">Comments ({{post.comment_count}})</a>
        </div>
        {% endif %}
      </div>
      {% endfor %}

    {% endif %}
  {% endif %}
{% endif %}

{% endblock %}